﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using HumanManagement.BusinessObjects;

namespace HumanManagement.DataAccess
{
	public class ContractTypeDA
	{

		#region ***** Init Methods ***** 
		public ContractTypeDA()
		{
		}
		#endregion

		#region ***** Get Methods ***** 
		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public ContractType Populate(IDataReader myReader)
		{
			ContractType obj = new ContractType();
			obj.ID = (int) myReader["ID"];
			obj.ContractType_Field = (string) myReader["ContractType"];
			obj.ContractPeriod = (decimal) myReader["ContractPeriod"];
			obj.Used = (string) myReader["Used"];
			obj.Description = (string) myReader["Description"];
			return obj;
		}

		/// <summary>
		/// Get ContractType by id
		/// </summary>
		/// <param name="id">ID</param>
		/// <returns>ContractType</returns>
		public ContractType GetByID(int id)
		{
			using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_ContractType_GetByID", Data.CreateParameter("ID", id)))
			{
				if (reader.Read())
				{
					return Populate(reader);
				}
				return null;
			}
		}

		/// <summary>
		/// Get all of ContractType
		/// </summary>
		/// <returns>List<<ContractType>></returns>
		public List<ContractType> GetList()
		{
			using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_ContractType_Get"))
			{
				List<ContractType> list = new List<ContractType>();
				while (reader.Read())
				{
				list.Add(Populate(reader));
				}
				return list;
			}
		}

		/// <summary>
		/// Get DataSet of ContractType
		/// </summary>
		/// <returns>DataSet</returns>
		public DataSet GetDataSet()
		{
			return SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure,"sproc_ContractType_Get");
		}


		/// <summary>
		/// Get all of ContractType paged
		/// </summary>
		/// <param name="recperpage">record per page</param>
		/// <param name="pageindex">page index</param>
		/// <returns>List<<ContractType>></returns>
		public List<ContractType> GetListPaged(int recperpage, int pageindex)
		{
			using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_ContractType_GetPaged"
							,Data.CreateParameter("recperpage", recperpage)
							,Data.CreateParameter("pageindex", pageindex)))
			{
				List<ContractType> list = new List<ContractType>();
				while (reader.Read())
				{
				list.Add(Populate(reader));
				}
				return list;
			}
		}

		/// <summary>
		/// Get DataSet of ContractType paged
		/// </summary>
		/// <param name="recperpage">record per page</param>
		/// <param name="pageindex">page index</param>
		/// <returns>DataSet</returns>
		public DataSet GetDataSetPaged(int recperpage, int pageindex)
		{
			return SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure,"sproc_ContractType_GetPaged"
							,Data.CreateParameter("recperpage", recperpage)
							,Data.CreateParameter("pageindex", pageindex));
		}





		#endregion

		#region ***** Add Update Delete Methods ***** 
		/// <summary>
		/// Add a new ContractType within ContractType database table
		/// </summary>
		/// <param name="obj">ContractType</param>
		/// <returns>key of table</returns>
		public int Add(ContractType obj)
		{
			DbParameter parameterItemID = Data.CreateParameter("ID", obj.ID);
			parameterItemID.Direction = ParameterDirection.Output;
			SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure,"sproc_ContractType_Add"
							,parameterItemID
							,Data.CreateParameter("ContractType", obj.ContractType_Field)
							,Data.CreateParameter("ContractPeriod", obj.ContractPeriod)
							,Data.CreateParameter("Used", obj.Used)
							,Data.CreateParameter("Description", obj.Description)
			);
			return (int)parameterItemID.Value;
		}

		/// <summary>
		/// updates the specified ContractType
		/// </summary>
		/// <param name="obj">ContractType</param>
		/// <returns></returns>
		public void Update(ContractType obj)
		{
			SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure,"sproc_ContractType_Update"
							,Data.CreateParameter("ID", obj.ID)
							,Data.CreateParameter("ContractType", obj.ContractType_Field)
							,Data.CreateParameter("ContractPeriod", obj.ContractPeriod)
							,Data.CreateParameter("Used", obj.Used)
							,Data.CreateParameter("Description", obj.Description)
			);
		}

		/// <summary>
		/// Delete the specified ContractType
		/// </summary>
		/// <param name="id">ID</param>
		/// <returns></returns>
		public void Delete(int id)
		{
			SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure,"sproc_ContractType_Delete", Data.CreateParameter("ID", id));
		}
		#endregion
	}
}
